package org.sn.jdish.designmode.responsibility;

import java.util.LinkedList;
import java.util.List;

/**
 * 责任链
 * 
 * @author snzigod@hotmail.com
 *
 */
public class HandlerChain implements IHandler {

	List<IHandler> handlers = new LinkedList<IHandler>();
	int index = 0;

	public HandlerChain addHandler(IHandler h) {
		handlers.add(h);
		return this;
	}

	@Override
	public void operation(HandlerChain hc) {
		if (index == handlers.size()) {
			return;
		}
		IHandler handler = handlers.get(index);
		index++;
		handler.operation(hc);
	}

}
